{% extends "../base.html" %}

{% block title %}
欢迎使用 {{ sys_config('SITE_NAME') }} 聊天工具!
{% end %}
{% block css %}
    <link rel="stylesheet" href="{{ static_url('layui/css/modules/layim/layim.css') }}">
    <link rel="stylesheet" href="{{ static_url('home/css/contextmenu.css') }}">
    <link rel="stylesheet" href="{{ static_url('home/css/menu.css') }}">
{% end %}
{% block body %}
{% include ../common/header.html %}

{% end %}
{% block javascript %}
<input type="hidden" name="curr_id" id="curr_id" value="{{ current_user['id'] }}">
<script src="{{ static_url('home/js/contextmenu.js') }}" charset="utf-8"></script>
<script src="{{ static_url('home/js/chat.js') }}" charset="utf-8"></script>
<script type="text/javascript">
    var token = '{{ token }}'
    if (token=='') {
        window.location = '/passport/login'
    }
    var user_list_url = '/chat/init'
    var im_name = "{{ sys_config('SITE_NAME') }} IM"

    var member_list_url = ''
    var upload_img_url = ''
    var upload_file_url = ''
    var msg_box_url = '/chat/msgbox'
    var msg_url = '/chat/notice'
    var find_url = '/friend/find'
    var chatlog_url = ''
    var change_sign_url = ''
    var chat_user_url = ''
    var save_audio_url = ''
    var get_noread_url = ''
    var join_group_url = ''

    var curr_id = "{{ current_user['id'] }}"
    var curr_uname = "{{ current_user['username']}}"
    var curr_avatar = "{{ current_user['avatar'] }}"
    var curr_sign = "{{ current_user['sign'] }}"

    var ws_scheme = window.location.protocol == 'https:' ? 'wss' : 'ws'
    var ws_host = ws_scheme + '://' + window.location.host + '/chat/websocket/?' + curr_id + '&token=' + token

    //layui绑定扩展
    layui.config({
        base: '/static/home/js/'
    }).extend({
        chat: 'chat',
    })
    layui.use(['layim', 'laytpl', 'jquery', 'chat'], function (layim, chat) {
        var $ = layui.jquery
        var chat = layui.chat
        var token = $('body').data('token')
        var rykey = $('body').data('rykey')


        chat.config({
            user: token,
            pwd: rykey ,
            layim: layim,
        })

        layim.config({
            init: {
                url: user_list_url, data: {}
            },
            //获取群成员
            members: {
                url: 'class/doAction.php?action=groupMembers', data: {}
            }
            //上传图片接口
            , uploadImage: {
                url: 'class/doAction.php?action=uploadImage' //（返回的数据格式见下文）
                , type: 'post' //默认post
            }
            //上传文件接口
            , uploadFile: {
                url: 'class/doAction.php?action=uploadFile' //
                , type: 'post' //默认post
            }
            //自定义皮肤
            ,uploadSkin: {
                url: 'class/doAction.php?action=uploadSkin'
                , type: 'post' //默认post
            }
            //选择系统皮肤
            ,systemSkin: {
                url: 'class/doAction.php?action=systemSkin'
                , type: 'post' //默认post
            }
            //获取推荐好友
            ,getRecommend:{
                url: 'class/doAction.php?action=getRecommend'
                , type: 'get' //默认
            }
            //查找好友总数
            ,findFriendTotal:{
                url: 'class/doAction.php?action=findFriendTotal'
                , type: 'get' //默认
            }
            //查找好友
            ,findFriend:{
                url: 'class/doAction.php?action=findFriend'
                , type: 'get' //默认
            }
            //获取好友资料
            ,getInformation:{
                url: 'class/doAction.php?action=getInformation'
                , type: 'get' //默认
            }
            //保存我的资料
            ,saveMyInformation:{
                url: 'class/doAction.php?action=saveMyInformation'
                , type: 'post' //默认
            }
            //提交建群信息
            ,commitGroupInfo:{
                url: 'class/doAction.php?action=commitGroupInfo'
                , type: 'get' //默认
            }
            //获取系统消息
            ,getMsgBox:{
                url: 'class/doAction.php?action=getMsgBox'
                , type: 'get' //默认post
            }
            //获取总的记录数
            ,getChatLogTotal:{
                url: 'class/doAction.php?action=getChatLogTotal'
                , type: 'get' //默认post
            }
            //获取历史记录
            ,getChatLog:{
                url: 'class/doAction.php?action=getChatLog'
                , type: 'get' //默认post
            }
            , isAudio: false //开启聊天工具栏音频
            , isVideo: false //开启聊天工具栏视频
            , groupMembers: true
            //扩展工具栏
            , tool: [{
                    alias: 'code'
                    , title: '代码'
                    , icon: '&#xe64e;'
                }]
            ,title: im_name
            ,copyright:true
            , initSkin: '1.jpg' //1-5 设置初始背景
            , notice: true //是否开启桌面消息提醒，默认false
            , systemNotice: false //是否开启系统消息提醒，默认false
            // , msgbox: layui.cache.dir + 'css/modules/layim/html/msgbox.html' //消息盒子页面地址，若不开启，剔除该项即可
            // , find: layui.cache.dir + 'css/modules/layim/html/find.html' //发现页面地址，若不开启，剔除该项即可
            , msgbox: msg_box_url
            , msg_url: msg_url
            , find: find_url
            , chatLog: layui.cache.dir + 'css/modules/layim/html/chatlog.html' //聊天记录页面地址，若不开启，剔除该项即可
            , createGroup: layui.cache.dir + 'css/modules/layim/html/createGroup.html' //创建群页面地址，若不开启，剔除该项即可
            , Information: layui.cache.dir + 'css/modules/layim/html/getInformation.html' //好友群资料页面
        })
    })
</script>
{% end %}
